﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Net.Mail;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm19 : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
            }
        }

        protected void linksendmail_Command(object sender, CommandEventArgs e)
        {
            
        }

        protected void btnsend_Click(object sender, EventArgs e)
        {
            MailMessage MyMessage = new MailMessage();
            MailAddress SendFrom = new MailAddress("eschool123g@gmail.com");
            if (FileUpload1.HasFile)
                FileUpload1.PostedFile.SaveAs(Server.MapPath("~/admin/attachments/" + FileUpload1.FileName));

            Attachment atc = new Attachment(Server.MapPath("~/admin/attachments/" + FileUpload1.FileName));
            MyMessage.Attachments.Add(atc);

            MyMessage.To.Add(tbto.Text);
            MyMessage.From = SendFrom;
            MyMessage.Subject = tbsubject.Text;
            MyMessage.Body = tbmsg.Text;
            System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("eschool123g@gmail.com","eschool@123");

            SmtpClient emailClient1 = new SmtpClient("smtp.gmail.com");
            emailClient1.EnableSsl = true;
            emailClient1.Port = 587;
            emailClient1.Credentials = basicAuthenticationInfo;
            emailClient1.Send(MyMessage);

            tbto.Text = ""; tbsubject.Text = ""; tbmsg.Text = ""; Label1.Visible = true;
            
            
            
            
            
            
            
            
            
            
            //DataTable dt = ad.GetRecords(Convert.ToInt64(Session["userid"]), "", "", "","", false, " and ");
            //MailMessage MyMessage = new MailMessage();
            //MailAddress SendFrom = new MailAddress(dt.Rows[0]["emailid"].ToString());
            ////Attachment atc = new Attachment(Server.MapPath("~/admin/school/" + "\\vlcsnap-33372.png"));
            ////MyMessage.Attachments.Add(atc);

            //MyMessage.To.Add(tbto.Text);
            //MyMessage.From = SendFrom;

            //MyMessage.Subject = tbsubject.Text;
            //MyMessage.Body = tbmsg.Text;
            
            //emailClient1.Send(MyMessage);
        }

   }
}
